package com.itheima.mapper;

import com.itheima.pojo.Dish;
import com.itheima.pojo.DishPage;
import com.itheima.pojo.Flavors;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface DishMapper {
    /**
     * 统计页面数量
     */
    @Select("select count(*) from dish")
    int count();

    /**
     * 菜品分页查询
     */
    List<DishPage> pageQuery(String name, Integer page, Integer pageSize);

    /**
     * 根据id查询菜品信息
     */
    @Select("select * from dish where id = #{id}")
    Dish selectInfo(String id);

    /**
     * 菜品下拉列表
     */
    @Select("select * from dish")
    List<Dish> pullDown();

    /**
     * 新增菜品
     */
    @Insert("insert into dish (id,name,price,code,image,description,status,categoryId ) values (#{id},#{name},#{price},#{code},#{image},#{description},#{status},#{categoryId})")
    int addDish(Dish dish);


    /**
     * 修改菜品
     */
    int update(Dish dish);

    /**
     * 菜品停售/起售
     */
    int updatestatus(String id, Integer status);

    /**
     * 删除菜品
     */
    int deleteWithFlavor(String id);

    /**
     * 查询全部菜品
     */
    @Select("select * from dish")
    List<Dish> selectAll();

    /**
     * 菜品列表
     */
    @Select("select * from dish where categoryId=#{categoryId} and status=#{status}")
    List<Dish> selectDish(String categoryId, Integer status);

    /**
     * 菜品详情
     */
    @Select("select d.id,d.type,d.name,d.categoryId,d.price,d.code,d.image,d.description,d.status,d.sort from dish d,setmealdishes s where s.dishId = d.id")
    List<Dish> selectDetails();
}
